home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / boot / czesc_2 / saferpatches / source.lha / Source / ShowStartup.a < prev   
Text File  |  1992-10-04  |  13KB  |  541 lines

  1.         include  "all.i"
  2.         include  "exec/types.i"
  3.  
  4. AbsExecBase    equ     4
  5. TRUE        equ     1
  6. FALSE        equ     0
  7. KICK204     equ     37
  8.  
  9. ;    Call a library function (Base in A6)
  10. libcall     macro
  11.         jsr    _LVO\1(A6)
  12.         endm
  13.  
  14. ;    Call a c (or assembler function)
  15. call        macro
  16.         bsr    @\1
  17.         endm
  18.  
  19. ;    Exports
  20.         xdef        @OpenWindowWithGad
  21.         xdef        @CloseWindowWithGad
  22.         xdef        @NewList
  23.         xdef        @Bin2Hex
  24.         xdef        @Mystrncpy
  25.         xdef        _LISTTEXT
  26.         xdef        _StdFunctions
  27.  
  28. ;    Imports
  29.         xref        @MainLoop
  30.         xref        _LinkerDB
  31.  
  32.         section     text,code
  33. ;************************
  34. ;* Program entry point    *
  35. ;************************
  36. ProgStart:    move.l        (AbsExecBase).w,A6
  37.         lea        _LinkerDB,A4
  38.  
  39. ;    Get the address of our task
  40.         move.l        ThisTask(A6),A5  ; A5 = ThisTask
  41.  
  42. ;    Started form CLI ?
  43.         moveq.l     #0,D0
  44.         tst.l        pr_CLI(A5)
  45.         bne        FromCLI        ; Yes
  46.  
  47. ;    Wait for startup message.
  48.         lea        pr_MsgPort(A5),A0
  49.         libcall     WaitPort        ; (A0=port)
  50.  
  51.         lea        pr_MsgPort(A5),A0
  52.         libcall     GetMsg        ; (A0=port)
  53.  
  54. FromCLI:    move.l        D0,_WBenchMsg-DT(A4)
  55.  
  56. ;    Open Dos library
  57.         lea        DOSNAME(PC),A1
  58.         moveq.l     #KICK204,D0        ; Need version 2.04
  59.         libcall     OpenLibrary     ; (A1=libname,D0=version)
  60.  
  61.         move.l        D0,_DOSBase-DT(A4)
  62.         beq        NoDos           ; No dos !!!?
  63.  
  64. ;    Parse arguments
  65.         call        ParseArgs        ; ()
  66.  
  67.         call        MainLoop
  68.  
  69. ;    Load A6 since Lattice may destroy it.
  70.         move.l        (AbsExecBase).W,A6
  71.  
  72. ;    Close dos.library
  73.         move.l        _DOSBase-DT(A4),A1
  74.         libcall     CloseLibrary
  75.  
  76. ;     If started from workbench we must reply the message
  77. NoDos:        move.l        _WBenchMsg-DT(A4),D3
  78.         beq        NoDos1
  79.  
  80.         libcall     Forbid        ; ()
  81.  
  82.         move.l        D3,A1
  83.         libcall     ReplyMsg        ; (A1=message)
  84.  
  85. NoDos1:     moveq.l     #0,D0
  86.         rts
  87.  
  88. ;************************************************************
  89. ;* ParseArgs(VOID)   get user arguments both CLI & WB       *
  90. ;*   return    D0 = NOFD, D1 = USEWINDOW            *
  91. ;************************************************************
  92.         STRUCTURE   Args,0
  93.         ULONG        arg_UseWindow
  94.         ULONG        arg_NoFD
  95.         LABEL        arg_SIZEOF
  96.  
  97. @ParseArgs:    movem.l     D2-D5/A2-A3/A6,-(SP)
  98.  
  99. ;    Workbench or cli arguments ?
  100.         lea        DefaultArgs(PC),A2
  101.         tst.l        _WBenchMsg-DT(A4)
  102.         bne        GetWBArgs
  103.  
  104. ;    Rda = ReadArgs(Template,&DefaultArgs,NULL)
  105. GetCLIArgs:    move.l        _DOSBase-DT(A4),A6
  106.         lea        TEMPLATETEXT(PC),A0
  107.         move.l        A0,D1
  108.         move.l        A2,D2
  109.         moveq.l     #0,D3
  110.         libcall     ReadArgs
  111.  
  112. ;   FreeArgs(Rda)
  113.         move.l        D0,D1
  114.         beq        ArgOK
  115.         libcall     FreeArgs
  116.  
  117.         bra        ArgOK
  118.  
  119. ;   Open icon library, any version will do
  120. GetWBArgs:    move.l        (AbsExecBase).W,A6
  121.         lea        ICONNAME(PC),A1
  122.         moveq.l     #0,D0
  123.         libcall     OpenLibrary     ; (A1=libName,D0=version)
  124.  
  125.         move.l        D0,D3
  126.         beq        NoIconLib
  127.  
  128. ;    OldCD = CurrentDir(WBenchMsg->sm_ArgList->wa_Lock)
  129.         move.l        _DOSBase-DT(A4),A6
  130.         move.l        _WBenchMsg-DT(A4),A3
  131.         move.l        sm_ArgList(A3),A3
  132.         move.l        wa_Lock(A3),D1
  133.         libcall     CurrentDir        ; (D1=lock)
  134.  
  135.         move.l        D0,D4
  136.  
  137. ;    DiskObj = GetDiskObject(WBenchMsg->sm_ArgList->wa_Name)
  138.         move.l        D3,A6        ; IconBase
  139.         move.l        wa_Name(A3),A0
  140.         libcall     GetDiskObject    ; (a0=name)
  141.  
  142.         move.l        D0,D5
  143.         beq        NoDiskObj
  144.  
  145. ;    ToolTypes = Dobj->do_ToolTypes
  146.         move.l        D0,A0
  147.         move.l        do_ToolTypes(A0),A3
  148.  
  149. ;  D3 = IconBase     A2 = DefaultArgs
  150. ;  D4 = OldCD         A3 = ToolTypes
  151. ;  D5 = DiskObject   A6 = IconBase
  152.  
  153. ;  Look for Tooltype NOFD
  154. ;  DefaultArgs.NoFD = FindToolType(ToolTypes,"NOFD")
  155.         move.l        A3,A0
  156.         lea        ARG_NOFD(PC),A1
  157.         libcall     FindToolType
  158.  
  159.         move.l        D0,arg_NoFD(A2)
  160.  
  161. ;  Workbench must use own screen.
  162. ;  DefaultArgs.UseWindow = TRUE;
  163.         moveq.l     #TRUE,D0
  164.         move.l        D0,arg_UseWindow(A2)
  165.  
  166. ;  FreeDiskObject(DiskObj)
  167.         move.l        D5,A0
  168.         libcall     FreeDiskObject
  169.  
  170. ;  if (OldCD)  CurrentDir(OldCD)
  171. NoDiskObj:    move.l        _DOSBase-DT(A4),A6
  172.         move.l        D4,D1
  173.         beq        CloseLib
  174.  
  175.         libcall     CurrentDir         ; (D1=lock)
  176.  
  177. ;  CloseLibrary(IconBase)
  178. CloseLib:    move.l        (AbsExecBase).W,A6
  179.         move.l        D3,A1
  180.         libcall     CloseLibrary     ; (A1=library)
  181.  
  182. ;  return arguments
  183. ArgOK:
  184. NoIconLib:    move.l        arg_NoFD(A2),D0
  185.         move.l        arg_UseWindow(A2),D1
  186.  
  187.         movem.l     (SP)+,D2-D5/A2-A3/A6
  188.         rts
  189.  
  190. ;********************************************************************
  191. ;* OpenWindowWithGad()  - Create gadgets and open the window we use *
  192. ;*   return   - Pointer to window structure if everything is OK     *
  193. ;********************************************************************
  194. @OpenWindowWithGad:
  195.         movem.l     D2-D3/A2-A3/A5-A6,-(SP)
  196.  
  197. ;   Create local variables
  198.         lea        -gng_SIZEOF(SP),SP
  199.  
  200. ;   Find the default screen
  201.         move.l        _IntuitionBase-DT(A4),A6
  202.         lea        WindowTags(PC),A3     ; A3 = Windowtags
  203.         suba.l        A0,A0
  204.         libcall     LockPubScreen      ; (A0=name)
  205.  
  206.         move.l        D0,wtag_PubScreen(A3)
  207.         beq        NoPubScreen
  208.  
  209. ;   Find size of window title bar
  210.         move.l        D0,A0
  211.         moveq.l     #0,D0
  212.         move.b        sc_WBorTop(A0),D0
  213.         move.l        sc_Font(A0),A1
  214.         add.w        ta_YSize(A1),D0
  215.         addq.w        #1,D0
  216.         move.w        D0,gng_TopEdge(SP)
  217.  
  218. ;   Get visual info
  219.         move.l        _GadToolsBase-DT(A4),A6
  220.         lea        TagDone(PC),A1
  221.         libcall     GetVisualInfoA    ; (A0=screen,A1=taglist)
  222.  
  223. ;   Fill in common stuff into the NewGad structure
  224.         move.l        D0,gng_VisualInfo(SP)
  225.         move.l        D0,_VisualInfo-DT(A4)
  226.         beq        NoVisualInfo
  227.  
  228. ;   Set font = Topaz 8
  229.         lea        Topaz8Font(PC),A0
  230.         move.l        A0,gng_TextAttr(SP)
  231.  
  232. ;   ID = 0  [never used]
  233.         clr.w        gng_GadgetID(SP)
  234.  
  235. ;   TopEdge
  236.         add.w        #15,gng_TopEdge(SP)
  237.  
  238. ;   Create a context to use
  239.         lea        wtag_Gadgets(A3),A0
  240.         clr.l        (A0)
  241.         libcall     CreateContext    ; (A0=glistptr)
  242.  
  243.         move.l        D0,A0
  244.  
  245. ; First gadget (LISTVIEW)
  246. ;   LeftEdge
  247.         move.w        #7,gng_LeftEdge(SP)
  248.  
  249. ;   Width and height
  250.         move.l        #$01900090,gng_Width(SP)  ; Both width and height
  251.  
  252. ;   Tags to use
  253.         lea        ListViewTags(PC),A2
  254.  
  255. ;   Gadget text
  256.         lea        _LISTTEXT(PC),A1
  257.         move.l        A1,gng_GadgetText(SP)
  258.  
  259.         move.l        SP,A1           ; A1 = NewGadget
  260.  
  261. ;   Gadget Flags
  262.         moveq.l     #NG_HIGHLABEL,D0
  263.         move.l        D0,gng_Flags(A1)
  264.  
  265. ;   Create gadget
  266.         moveq.l     #LISTVIEW_KIND,D0
  267.         libcall     CreateGadgetA    ; (D0=kind,A0=gad,A1=ng,A2=taglist)
  268.  
  269. ; Second gadget (BUTTON)
  270. ;   Gadget Text
  271.         lea        EXITTEXT(PC),A0
  272.         move.l        A0,gng_GadgetText(SP)
  273.  
  274.         move.l        D0,A0        ; Context
  275.  
  276. ;   Left and top
  277.         add.w        #144,gng_TopEdge(SP)
  278.         move.w        #168,gng_LeftEdge(SP)
  279.  
  280. ;   Width and height
  281.         move.l        #$004c000e,gng_Width(SP)
  282.  
  283. ;   Tags
  284.         lea        ButtonTags(PC),A2
  285.  
  286.         move.l        SP,A1           ; A1 = NewGadget
  287.  
  288. ; Flags
  289.         moveq.l     #PLACETEXT_IN,D0
  290.         move.l        D0,gng_Flags(A1)
  291.  
  292.         moveq.l     #BUTTON_KIND,D0
  293.         libcall     CreateGadgetA    ; (D0=kind,A0=gad,A1=ng,A2=taglist)
  294.  
  295.         tst.l        D0
  296.         beq        NoGad
  297.  
  298. ;   open window
  299.         move.l        _IntuitionBase-DT(A4),A6
  300.         suba.l        A0,A0
  301.         move.l        A3,A1        ; WindowTags
  302.         libcall     OpenWindowTagList    ; (A0=newWindow,A1=tagList)
  303.  
  304.         move.l        D0,D2
  305.  
  306.         beq        NoWindow
  307.  
  308. ;   Draw the gadgets
  309.         move.l        _GadToolsBase-DT(A4),A6
  310.         move.l        D0,A0        ; Window
  311.         sub.l        A1,A1
  312.         libcall     GT_RefreshWindow    ; (A0=win,A1=req)
  313.  
  314.         bra        OpenOk
  315.  
  316. NoWindow:    move.l        _GadToolsBase-DT(A4),A6
  317. NoGad:        move.l        wtag_Gadgets(A3),A0
  318.         libcall     FreeGadgets     ; (A0=gad)
  319.  
  320.         move.l        _VisualInfo-DT(A4),A0
  321.         libcall     FreeVisualInfo    ; (A0=vi)
  322.  
  323. NoVisualInfo:    move.l        wtag_PubScreen(A3),A1
  324.         sub.l        A0,A0
  325.         move.l        _IntuitionBase-DT(A4),A6
  326.         libcall     UnlockPubScreen        ; (A0=name,A1=screen)
  327.  
  328. NoPubScreen:    moveq.l     #0,D2
  329.  
  330. OpenOk:     lea        gng_SIZEOF(SP),SP
  331.  
  332.         move.l        D2,D0
  333.         movem.l     (SP)+,D2-D3/A2-A3/A5-A6
  334.         rts
  335.  
  336. ;*************************************************************************
  337. ;* VOID CloseWindowWithGad(Window) - close the window and remove gadgets *
  338. ;*************************************************************************
  339. @CloseWindowWithGad:
  340.         move.l        A2,-(SP)
  341.         move.l        A6,-(SP)
  342.  
  343.         move.l        _IntuitionBase-DT(A4),A6
  344.  
  345.         lea        WindowTags(PC),A2
  346.  
  347. ;    Remove the window from the screen
  348.         libcall     CloseWindow     ; (A0=window)
  349.  
  350. ;    Clean up the gadgets
  351.         move.l        _GadToolsBase-DT(A4),A6
  352.         move.l        wtag_Gadgets(A2),A0
  353.         libcall     FreeGadgets     ; (A0=gad)
  354.  
  355. ;    No need for the Visual info anymore
  356.         move.l        _VisualInfo-DT(A4),A0
  357.         libcall     FreeVisualInfo    ; (A0=vi)
  358.  
  359. ;    Release the screen
  360.         move.l        _IntuitionBase-DT(A4),A6
  361.         move.l        wtag_PubScreen(A2),A1
  362.         sub.l        A0,A0
  363.         libcall     UnlockPubScreen    ; (A0=name,A1=screen)
  364.  
  365.         move.l        (SP)+,A6
  366.         move.l        (SP)+,A2
  367.         rts
  368.  
  369. ;*******************************************************
  370. ;* NewList(List)  - replacement for amiga.lib version. *
  371. ;*          - uses register parameters.           *
  372. ;*******************************************************
  373. @NewList:    move.l        A0,LH_HEAD(A0)
  374.         addq.l        #4,LH_HEAD(A0)
  375.         clr.l        LH_TAIL(A0)
  376.         move.l        A0,LH_TAILPRED(A0)
  377.         rts
  378.  
  379. ;***********************************************************************
  380. ;* Bin2Hex(Buffer,Value, Length) - Converts a long to ascii hex string *
  381. ;*   Buffer - where to store result.                       *
  382. ;*   Value  - Value to convert.                        *
  383. ;*   Length - No of hex digits to use. (max 8)                         *
  384. ;*                                       *
  385. ;* Does not print anything if value == 0                   *
  386. ;***********************************************************************
  387. @Bin2Hex:    move.l        D2,-(SP)
  388.         move.l        D3,-(SP)
  389.  
  390. ; skip first digits if length < 8
  391.         moveq.l     #8,D2
  392. 1$        cmp.w        D2,D1
  393.         beq.b        2$
  394.  
  395.         lsl.l        #4,D0
  396.         subq.w        #1,D2
  397.         bra        1$
  398.  
  399. ; Start with blanks
  400. 2$        moveq.l     #FALSE,D2
  401.  
  402. NextChar:    move.l        D0,D3
  403.         lsl.l        #4,D0
  404.         lsr.l        #8,D3     ; There must be an
  405.         lsr.l        #8,D3     ; easier way to do this
  406.         lsr.l        #8,D3
  407.         lsr.l        #4,D3
  408.         bne        CharFound
  409.  
  410. ;  Have we printed anything yet ?
  411.         tst.w        D2
  412.         bne        CharFound
  413.  
  414.         moveq.l     #' ',D3
  415.         bra        WriteChar
  416.  
  417. ;  Convert to ASCII
  418. CharFound:    lea        HEXCHARS(PC),A1
  419.         move.b        0(A1,D3.W),D3
  420.         moveq.l     #TRUE,D2
  421.  
  422. WriteChar:    move.b        D3,(A0)+
  423.         subq.w        #1,D1
  424.         bne        NextChar
  425.  
  426. ;  End the string
  427.         move.b        D1,(A0)
  428.         move.l        (SP)+,D3
  429.         move.l        (SP)+,D2
  430.         rts
  431.  
  432. ;*******************************************************
  433. ;* ULONG Mystrlen(String) - A short (and fast) strlen. *
  434. ;*                               *
  435. ;*   String   - pointer to a null-terminated string.   *
  436. ;*   return   - length of string. max 32767 chars      *
  437. ;*******************************************************
  438. ;@Mystrlen:     moveq.l     #-1,D0
  439. ;1$         tst.b         (A0)+
  440. ;         dbeq         D0,1$
  441. ;         neg.l         D0
  442. ;         subq.l      #1,D0
  443. ;         rts
  444.  
  445. ;**************************************************************
  446. ;* Mystrncpy(Dest,Source,Count) - A short (and fast) strncpy  *
  447. ;*                                  *
  448. ;*   Source,Dest  - strings to copy.                  *
  449. ;*   Count      - max length of destination              *
  450. ;**************************************************************
  451. @Mystrncpy:    move.b        (A1)+,(A0)+
  452.         dbeq        D0,@Mystrncpy
  453.         rts
  454.  
  455. ;*****************************************************************
  456. ;*               Data area                 *
  457. ;*****************************************************************
  458.  
  459. ;    Default arguments (used by ReadArgs)
  460. DefaultArgs:    dc.l        FALSE    ; arg_UseWindow
  461.         dc.l        FALSE    ; arg_NoFD
  462. ICONNAME:    dc.b        'icon.library',0
  463.         cnop        0,2
  464. DOSNAME:    dc.b        'dos.library',0
  465.         cnop        0,2
  466. TOPAZNAME:    dc.b        'topaz.font',0
  467.         cnop        0,2
  468. ARG_NOFD:    dc.b        'NOFD',0
  469.         cnop        0,2
  470. TEMPLATETEXT:    dc.b        'USEWINDOW/S,NOFD/S',0
  471.         cnop        0,2
  472. HEXCHARS:    dc.b        '0123456789abcdef'
  473.         cnop        0,2
  474. _LISTTEXT:    dc.b        'Offset    Old       New   Name                  ',0
  475.         cnop        0,2
  476. _StdFunctions:    dc.b        'Lib_Open',0,0,0,0
  477.         dc.b        'Lib_Close',0,0,0
  478.         dc.b        'Lib_Expunge',0
  479.         dc.b        'Lib_Reserved',0
  480.         cnop        0,2
  481. EXITTEXT:    dc.b        'E_xit',0
  482.         cnop        0,2
  483. WINDOWTITLE:    dc.b        'ShowPatches 2.0 ',$a9,' 1992 Martin Adrian',0
  484.         cnop        0,2
  485.         dc.b        '$VER: ShowPatch 2.0 (3-Oct-92)',0
  486.         cnop        0,2
  487.  
  488. WindowIDCMP:    set        LISTVIEWIDCMP!BUTTONIDCMP!IDCMP_GADGETUP
  489. WindowIDCMP:    set        WindowIDCMP!IDCMP_CLOSEWINDOW!IDCMP_VANILLAKEY
  490. WindowIDCMP:    set        WindowIDCMP!IDCMP_REFRESHWINDOW
  491.  
  492. WindowFlags:    set        WFLG_DRAGBAR!WFLG_DEPTHGADGET!WFLG_CLOSEGADGET
  493. WindowFlags:    set        WindowFlags!WFLG_SIMPLE_REFRESH!WFLG_ACTIVATE
  494. WindowFlags:    set        WindowFlags!WFLG_RMBTRAP
  495.  
  496. WindowTags:    dc.l        WA_Left,0
  497.         dc.l        WA_Top,0
  498.         dc.l        WA_InnerWidth,405
  499.         dc.l        WA_InnerHeight,174
  500.         dc.l        WA_AutoAdjust,TRUE
  501.         dc.l        WA_IDCMP,WindowIDCMP
  502.         dc.l        WA_Flags,WindowFlags
  503.         dc.l        WA_Title,WINDOWTITLE
  504. WPub:        dc.l        WA_PubScreen,0    ; filled in
  505. WGad:        dc.l        WA_Gadgets,0    ; filled in
  506.         dc.l        TAG_DONE
  507.  
  508. wtag_Gadgets:    equ        (WGad-WindowTags)+4
  509. wtag_PubScreen: equ        (WPub-WindowTags)+4
  510.  
  511. ListViewTags:    dc.l         GTLV_Labels,_List
  512.         dc.l         GTLV_ReadOnly,TRUE
  513. ButtonTags:    dc.l         GT_Underscore,'_'
  514. TagDone:    dc.l         TAG_DONE
  515.  
  516. Topaz8Font:    dc.l        TOPAZNAME        ; ta_Name
  517.         dc.w        8            ; ta_YSize
  518.         dc.b        FS_NORMAL        ; ta_Style
  519.         dc.b        FPF_ROMFONT     ; ta_Flags
  520.  
  521.         section     __MERGED,bss
  522. DT        equ        *
  523.  
  524.         xdef        _DOSBase
  525.         xdef        _Fh
  526.         xdef        _FDOffset
  527.         xdef        _GadToolsBase
  528.         xdef        _IntuitionBase
  529.         xdef        _List
  530.  
  531. _DOSBase    ds.l        1
  532. _Fh        ds.l        1
  533. _FDOffset    ds.l        1
  534. _GadToolsBase    ds.l        1
  535. _IntuitionBase    ds.l        1
  536. _List        ds.b        LH_SIZE
  537. _WBenchMsg    ds.l        1
  538. _VisualInfo    ds.l        1
  539.  
  540.         end
  541.